class Attachment < ActiveRecord::Base
  belongs_to :entity, :polymorphic => true
  
  attr_reader :image_only
  attr_writer :image_only
  # 使用 image_only 属性控制是否启用 content_type 验证
  validates_format_of :content_type, :with => /^image/, :message => "请上传图片文件", :if => :image_only
  
  def load_from_file_field(file_field)
    self.name = file_field.original_filename
    self.content_type = file_field.content_type.chomp
    self.data = file_field.read
  end
  
  
  
end
